import { defineStore } from 'pinia'
import { StoreType, type IDict } from './type'

export const useDictStore = defineStore(StoreType.DICT, {
  state: () => {
    return {
      dict: [] as IDict[]
    }
  },
  actions: {
    /**获取字典 */
    async getDictList() {},

    /**根据id获取字典 */
    getDictById(id: string) {
      return this.dict.find(item => item.id === id)
    },

    /**根据字典类型获取字典 */
    getDictByType(type: string) {
      return this.dict.filter(item => item.dictType === type)
    },

    /**存储字典 */
    setDict(dictList: IDict[]) {
      this.dict = dictList
    }
  }
})
